package com.julis.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import butterknife.BindView;
import butterknife.ButterKnife;
import de.greenrobot.event.EventBus;
import com.julis.R;
import com.julis.bean.FanHui;
import com.julis.bean.MyEvent;
import com.customview.InputViewOnlyShow;


/**
 * 分类
 */
public class ObuInfo1_Fragment extends Fragment {
    View view;
    @BindView(R.id.ipv_issuer_id)
    InputViewOnlyShow ipvIssuerId;
    @BindView(R.id.ipv_contract_type)
    InputViewOnlyShow ipvContractType;
    @BindView(R.id.ipv_contract_version)
    InputViewOnlyShow ipvContractVersion;
    @BindView(R.id.ipv_contract_no)
    InputViewOnlyShow ipvContractNo;
    @BindView(R.id.ipv_start_date)
    InputViewOnlyShow ipvStartDate;
    @BindView(R.id.ipv_end_date)
    InputViewOnlyShow ipvEndDate;
    @BindView(R.id.ipv_remove_flag)
    InputViewOnlyShow ipvRemoveFlag;
    @BindView(R.id.ipv_obumac)
    InputViewOnlyShow ipv_obumac;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        if (view == null) {
            view = View.inflate(getActivity(), R.layout.fragment_obuinfo, null);

            ButterKnife.bind(this, view);
            EventBus.getDefault().register(this);
        }
        ViewGroup parent = (ViewGroup) view.getParent();
        if (parent != null) {
            parent.removeView(view);
        }

        return view;
    }

    //数据分发

    public void onEventMainThread(MyEvent event) {
        String code = event.getCode();
        if (code.equals("1")) {
            FanHui fanHui = event.getFanHui();
            Bundle bundle = fanHui.getBundle();
            initShowViews(bundle);
        }else if (code.equals("3")) {
            FanHui fanHui = event.getFanHui();
            Bundle bundle = fanHui.getBundle();
            bundle.putString("OBUSTATUS","未拆");
            initShowViews(bundle);
        }else{
            ipv_obumac.setEditText("");
            ipvIssuerId.setEditText("");
            ipvContractType.setEditText("");
            ipvContractVersion.setEditText( "");
            ipvContractNo.setEditText("");
            ipvStartDate.setEditText("");
            ipvEndDate.setEditText("");
            ipvRemoveFlag.setEditText(  "");
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }
    private void initShowViews(Bundle bundle) {

        ipv_obumac.setEditText(bundle.getString("OBUMAC"));
        ipvIssuerId.setEditText(bundle.getString("OBUISSUER"));
        ipvContractType.setEditText(bundle.getString("OBUCONTRACTTYPE"));
        ipvContractVersion.setEditText( bundle.getString("OBUCONTRACT"));
        ipvContractNo.setEditText(bundle.getString("OBUSERIALNUMBER"));
        ipvStartDate.setEditText(bundle.getString("OBUDATE"));
        ipvEndDate.setEditText(bundle.getString("OBUDATE2"));
        ipvRemoveFlag.setEditText(  bundle.getString("OBUSTATUS"));
        Log.e("test", "数据：" +bundle.getString("OBUSTATUS"));
    }

}
